Written by Marco Piovanelli, <mailto:piovanel@kagi.com>
Introduction
KQ AESend is an extension for KeyQuencer, a powerful macro utility written by Alessandro Levi Montalcini, that gives KeyQuencer macros the ability to send Apple events to any process running on your machine.
Apple events are the low-level messages Macintosh applications use to talk to each other, and the basis for scripting systems like AppleScript™ and Frontier™. AESend lets advanced scripters and power users access the raw power of Apple events from KeyQuencer, without the overhead involved by a scripting system. AESend is fast and flexible, but also difficult to use for non-programmer types, because it requires a good understanding of the underpinnings of Apple events. Fortunately, you don’t need to be a programmer to take advantage of KQ AESend, as the package comes with 48 ready-to-use sample macros based entirely on this extension.
Requirements
KQ AESend requires version 2.0 of KeyQuencer or KeyQuencer Lite, and of course, applications that can be effectively driven by Apple events. Many of the sample macros require the Scriptable Finder or some standard scripting additions, all of which are installed by default on machines running MacOS 7.5 or later.
Sample Macros
Here’s a brief description of what some of the included macros do. Let’s start with the macros which rely on the scriptable Finder.
Open with ResEdit, Open with Script Editor and Open with Style tell the Finder to open the selected items with a specific application, and are equivalent to dragging the selection onto the application icon.
Open Apple Menu Items, Open Control Panels, Open Extensions, Open KQ Extensions, Open Preferences, Open Scripting Additions and Open System Folder tell the Finder to open a specific folder.
Expand decodes/decompresses the selected items using StuffIt Expander™, while Stuff does the reverse operation using DropStuff™. Mount Disk Image mounts disk images using ShrinkWrap™.
Add to Apple Menu puts aliases to the selected items in the Apple Menu Items folder, whereas Make Alias on Desktop creates the aliases on the desktop. Reveal Original reveals the original item the selected alias points to, and Show Original Info opens the Finder’s info window for it.
Several View By macros let you change the view of a Finder’s window.
Some macros are supposed to work not just with the Finder, but with any scriptable application that supports the Standard Suite of events: they include Zoom In, Zoom Out and Cycle Windows.
Set Font/Size to Monaco 9 is a macro to use in conjunction with a scriptable text editor like Style or Tex-Edit Plus 2.0.
Finally, there are several macros that exploit some standard scripting additions (also known as osaxen) to set the monitor depth or the speaker volume.
Writing Your Own Macros: A Short Tutorial
This section explains the syntax used by KQ AESend to encode Apple events.
where <target> is the creator type of the target application (e.g., MACS for the Finder, MMan for Claris Emailer, etc.), <eventClass> / <eventID> are two four-letter codes that uniquely identify the Apple event you want to send, and zero, one or more <keyword> / <param> pairs specify the parameters of the Apple event. Apple events parameters are identified by four-letter keywords as well.
Here’s a trivial macro that simply quits the Finder:
AESend MACS aevt quit
As you can see, the “quit” event is identified by the codes aevt / quit and doesn’t need any parameter. Here’s a macro that sends an event with one parameter:
The codes GURL / GURL stand for the “Get URL” event, the kind sent by Internet Config when you command-click a URL in an IC-aware application. This event needs a URL in the direct parameter, which is specified by the four-letter keyword ----: since KeyQuencer interprets a double dash as the beginning of a comment, you have to quote the keyword, or you can use a single dash as a convenient shortcut, like this:
By default, KQ AESend assumes parameters are strings, but things really get interesting when you start using object specifiers, the most common kind of parameter in modern scriptable applications that comply with the so-called Apple Event Object Model. To build an object specifier, you need the following pieces: a class ID that specifies what kind of object you’re talking about (e.g., a folder, a word or a mailbox), a key that specifies how to access that object within its container (e.g., the third one from the end, or the one named “report”) and optionally, another (nested) object specifier which identifies the container of the object you’re referring to (like “the second word of paragraph 5”).
Theory apart, let’s see what object specifiers looks like in KQ AESend with a few real-world examples:
KQ AESend AppleScript
========= ===========
sele• selection
pcli• clipboard
cwin[1]• window 1
cwin[untitled]• window "untitled"
cwin[*]• every window
appf[_RSED]• application file id "RSED"
cwin[1]•pnam name of window 1
cwin[1]•cwor[1] word 1 of window 1
cwin[1]•cwor[1]•font font of word 1 of window 1
All object specifiers must contain at least one bullet (“•”), or they won’t be recognized as such. If the object specifier doesn’t have a container, the bullet must be the last character, while if it does, the bullet is used as a separator between nested object specifiers. When you have nested object specifiers, the outermost must appear first on the line, and the innermost last (in AppleScript, the ordering is reversed). Keys are written in brackets after the class ID: you can identify objects by index, by name or by ID. The ID key form requires an underscore character before the ID code.
Since KQ AESend deals with raw events, it has no concept of dictionaries or glue tables, and figuring out the ubiquitous four-letter codes for events and object classes can be hard. Here’s a list of some common verbs (events):
KQ AESend AppleScript
========= ===========
misc actv activate
core clos close
core crel make
aevt odoc open
core save save
misc mvis show
core setd set
aevt quit quit
And here’s a list of common nouns (classes and properties):
KQ AESend AppleScript
========= ===========
appf application file
'cha ' character
pcli clipboard
cRGB color
docu document
file file
cfol folder
font font
pidx index
clin line
pnam name
cpar paragraph
sele selection
ptsz size
ctxt text
cwin window
cwor word
Distribution
KQ AESend is freeware: you may use it free of charge and give it to others, but you may not distribute altered copies. Publishers can include KQ AESend in floppy and CD-ROM shareware collections without having to notify me.
About KeyQuencer
KeyQuencer was written by Alessandro Levi Montalcini and is published by Binary Software, Inc.:
<http://www.binarysoft.com>
<mailto:keyquencer@binarysoft.com>
KeyQuencer Lite is a stripped-down, US$ 20 shareware version of KeyQuencer.